<?php


class core_remote_curl {
	function send($url,$headers=array(),$post_string='',$crt_path='',$return_with_header=1) {
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_HEADER, (bool)$return_with_header);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
		
		if(!empty($headers)){
			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		}
		if($post_string){
			curl_setopt($ch, CURLOPT_POST, TRUE);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
		}
		if($crt_path){
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
			curl_setopt($ch, CURLOPT_CAINFO, $crt_path);
		}else{
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		}
		$response = curl_exec($ch);
		curl_close($ch);
		return $response;
	}
	function getheader($response) {
		$pos = strpos($response,"\r\n\r\n");
		return substr($response,0,$pos);
	}
	function getbody($response) {
		$pos = strpos($response,"\r\n\r\n");
		return substr($response,$pos+4);
	}
}